﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace FierceWar
{
	public class PauseScreen : Screen
	{
		private string _message1;
		private string _message2;
		private Vector2 _fontMessage1;
		private Vector2 _fontMessage2;
		private Vector2 _position1;
		private Vector2 _position2;
		private Rectangle _bounds;

		public Screen BackgroundScreen;

		public PauseScreen(GameResources resources, EventHandler screenEvent)
			: base(resources, screenEvent)
		{
			_message1 = "Game Paused";
			_message2 = "Press 'P' to Resume";
			_fontMessage1 = Resources.PauseFont.MeasureString(_message1);
			_fontMessage2 = Resources.PauseFont.MeasureString(_message2);
			_position1 = new Vector2(
					(Resources.GraphicsDevice.Viewport.Width - _fontMessage1.X) / 2,
					(Resources.GraphicsDevice.Viewport.Height - _fontMessage1.Y) / 2);
			_position2 = new Vector2(
					(Resources.GraphicsDevice.Viewport.Width - _fontMessage2.X) / 2,
					(Resources.GraphicsDevice.Viewport.Height - _fontMessage2.Y) / 2);
			_bounds = new Rectangle(
				0, (Resources.GraphicsDevice.Viewport.Height - 200) / 2,
				Resources.GraphicsDevice.Viewport.Width, 200);
		}

		public override void Update(GameTime gameTime)
		{
			base.Update(gameTime);

			if (KeyboardInput.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.P))
			{
				ScreenEvent.Invoke(this, new EventArgs());
			}
		}

		public override void Draw(GameTime gameTime)
		{
			base.Draw(gameTime);

			if (BackgroundScreen != null)
			{
				BackgroundScreen.Draw(gameTime); 
			}

			DrawPausedMessage();
		}

		private void DrawPausedMessage()
		{
			FadeToBlack(0.6f);
			Resources.SpriteBatch.Draw(Resources.BlankTexture,
				_bounds, Color.Black * 0.5f);
			Resources.SpriteBatch.DrawString(Resources.PauseFont, _message1,
				_position1 - new Vector2(0.0f, 28.0f), Color.Black);
			Resources.SpriteBatch.DrawString(Resources.PauseFont, _message1,
				_position1 - new Vector2(0.0f, 30.0f), Color.White);
			Resources.SpriteBatch.DrawString(Resources.PauseFont, _message2,
				_position2 + new Vector2(0.0f, 32.0f), Color.Black);
			Resources.SpriteBatch.DrawString(Resources.PauseFont, _message2,
				_position2 + new Vector2(0.0f, 30.0f), Color.White);
		}
	}
}
